package com.example.webview;


import androidx.appcompat.app.AppCompatActivity;

import android.os.Build;
import android.os.Bundle;

import android.util.Log;
import android.view.View;
import android.webkit.ValueCallback;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import android.widget.Button;
import android.widget.TextView;

import org.json.JSONException;
import org.json.JSONObject;


public class MainActivity extends AppCompatActivity {

    private WebView webView;
    private TextView textView;
    private TextView sessionText;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String str = """
                         int a;
                     """;

        webView = findViewById(R.id.webView);

        textView = findViewById(R.id.text);
        sessionText = findViewById(R.id.session);
        Button button = findViewById(R.id.button);



        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);



        webView.loadUrl("https://seatreservation.sdwu.edu.cn/libseat/#/login/");

        button.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                // 在点击按钮时，打印 "Hello World" 到控制台
                System.out.println("Hello World");
                


                textView.setText("版本在19");


                webView.evaluateJavascript("sessionStorage.getItem('userInfo');", new ValueCallback<String>() {
                    @Override
                    public void onReceiveValue(String value) {
                        // 获取到的数据，可以把数据存入静态对象中，以便其它webview设置sessionStorage数据
                        Log.d("TAG", "Session storage data: " + value);
                    }
                });


            }
        });


    }


}



